package com.whmnx.chitchat.ui.my;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;

import com.tencent.imsdk.TIMCallBack;
import com.tencent.imsdk.TIMFriendshipManager;
import com.tencent.imsdk.TIMUserProfile;
import com.whmnx.chitchat.R;
import com.whmnx.chitchat.base.BaseActivity;
import com.whmnx.chitchat.bean.LoginBean;
import com.whmnx.chitchat.constants.Constants;
import com.whmnx.chitchat.event.EventConstants;
import com.whmnx.chitchat.event.MessageEvent;
import com.whmnx.chitchat.http.CallBack;
import com.whmnx.chitchat.http.HttpClient;
import com.whmnx.chitchat.main.RegisterActivity;
import com.whmnx.chitchat.utils.PhotoUtil;
import com.whmnx.chitchat.utils.SPUtil;
import com.whmnx.chitchat.utils.UItils;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * author : huang
 * date   : 2020/7/22 0022 18:18
 * version: 1.0
 *
 * @author Administrator
 */
public class ChangeInfoActivity extends BaseActivity {
    @BindView(R.id.et_info)
    EditText etInfo;

    @Override
    protected void loadViewLayout() {
        int type2 = getIntent().getIntExtra("type", 0);
        String group_id = getIntent().getStringExtra("group_id");
        setContentView(R.layout.change_info_activity);
        if (type2 == 13){
            setTitle("备注设置");
        }else if (type2 == 2){
            setTitle("修改群聊名称");
        }else if (type2 == 3){
            setTitle("修改本群昵称");
        }else if (type2 == 1){
            setTitle("修改群公告");
        }

        setRringTitle("完成");
        tv_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(etInfo.getText().toString().trim())) {
                    UItils.showToastSafe("请输入内容");
                    return;
                }
                if (type2 == 1) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("GroupID", group_id);
                    params.put("Notice", etInfo.getText().toString().trim());
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    HttpClient.get(ChangeInfoActivity.this, Constants.GETUPDATEGROUPNOTICE, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            // SPUtil.put(Constants.NICKNAME,etInfo.getText().toString().trim());
                            Intent intent = new Intent();
                            intent.putExtra("name", etInfo.getText().toString().trim());
                            setResult(RESULT_OK, intent);
                            finish();
                        }
                    });
                } else if (type2 == 13) {
                    Map<String, Object> params = new HashMap<>();
                    params.put("Remake", etInfo.getText().toString().trim());
                    params.put("Mobile", SPUtil.getString(Constants.PHONE));
                    params.put("FriendMobile", getIntent().getStringExtra("FriendMobile"));
                    HttpClient.get(ChangeInfoActivity.this, Constants.GETUPDATEFRIENDREMAKE, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            // SPUtil.put(Constants.NICKNAME,etInfo.getText().toString().trim());
                            Intent intent = new Intent();
                            intent.putExtra("name", etInfo.getText().toString().trim());
                            setResult(RESULT_OK, intent);
                            finish();
                        }
                    });
                } else if (type2 == 2){  //修改群昵称
                    Map<String, Object> params = new HashMap<>();
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    params.put("Name", etInfo.getText().toString().trim());
                    params.put("GroupID", getIntent().getStringExtra("GroupID"));
                    HttpClient.get(ChangeInfoActivity.this, Constants.GETUPDATEGROUPNAME, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                           // SPUtil.put(Constants.NICKNAME, etInfo.getText().toString().trim());
                            Intent intent = new Intent();
                            intent.putExtra("name", etInfo.getText().toString().trim());
                            setResult(RESULT_OK, intent);
                            MessageEvent messageEvent2 = new MessageEvent();
                            messageEvent2.setMessageKey(EventConstants.NICKNAME);
                            messageEvent2.setMessageValue(etInfo.getText().toString().trim());
                            EventBus.getDefault().post(messageEvent2);
                            finish();
                        }
                    });
                }else if (type2 == 3){ //用户修改自己在群的昵称
                    Map<String, Object> params = new HashMap<>();
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    params.put("UserGroupName", etInfo.getText().toString().trim());
                    params.put("GroupID", getIntent().getStringExtra("GroupID"));
                    HttpClient.get(ChangeInfoActivity.this, Constants.GETUPDATEUSERGROUPNAME, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            // SPUtil.put(Constants.NICKNAME, etInfo.getText().toString().trim());
                            Intent intent = new Intent();
                            intent.putExtra("name", etInfo.getText().toString().trim());
                            setResult(RESULT_OK, intent);
                            MessageEvent messageEvent = new MessageEvent();
                            messageEvent.setMessageKey(EventConstants.ADDFRIENDS);
                            EventBus.getDefault().post(messageEvent);
                            finish();
                        }
                    });
                }else {
                    Map<String, Object> params = new HashMap<>();
                    params.put("UserID", SPUtil.getString(Constants.USERID));
                    params.put("NikeName", etInfo.getText().toString().trim());
                    HttpClient.get(ChangeInfoActivity.this, Constants.GETUPDATENIKENAME, params, new CallBack<LoginBean>() {
                        @Override
                        public void onSuccess(LoginBean result) {
                            SPUtil.put(Constants.NICKNAME, etInfo.getText().toString().trim());
                            Intent intent = new Intent();
                            intent.putExtra("name", etInfo.getText().toString().trim());
                            setResult(RESULT_OK, intent);
                            finish();
                        }
                    });
                }
            }
        });
    }

    @Override
    protected void loadData() {


    }




}
